package com.shijie.newvideo;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.util.TypedValue;

/**
 * @author zhangdunxiang
 * @date 2024/9/25
 * 功能：
 */
public class DeviceInfoUtil {
    public static int dp2px(Context context, float dpVal) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                dpVal, context.getResources().getDisplayMetrics());
    }

    /**
     * 当前activity是否销毁了
     */
    public static boolean currentActviityIsDestory(Activity activity) {
        boolean result = false;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (activity == null || activity.isDestroyed() || activity.isFinishing()) {
                result = true;
            }
        } else {
            if (activity == null || activity.isFinishing()) {
                result = true;
            }
        }
        return result;
    }
}
